package com.guigu.qingcheng.servicegoods.controller;


import com.guigu.qingcheng.pojo.goods.TbCategoryBrand;
import com.guigu.qingcheng.servicegoods.service.TbCategoryBrandService;
import com.guigu.qingcheng.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("/catebrand")
public class TbCategoryBrandController {

    @Autowired
    private TbCategoryBrandService categoryBrandService;

    //查询所有
    @GetMapping("findAll")
    public R findAll(){
        List<TbCategoryBrand> list = this.categoryBrandService.list(null);
        if (list.size()>0)
            return R.ok().data("categoryBand",list);
        return R.error().data("categoryBand",list);
    }
    //根据id查询
    /*@GetMapping("findById")
    public R findById(@RequestParam("id") int id){
        TbCategoryBrand tbCategoryBrand = new TbCategoryBrand();
        tbCategoryBrand = categoryBrandService.getById(id);
        return R.ok().data("catebrand",tbCategoryBrand);
    }*/

    //增加数据
    @PostMapping("add")
    public R addCateBrand(@RequestBody TbCategoryBrand tbCategoryBrand){
        Boolean flag = categoryBrandService.save(tbCategoryBrand);
        if (flag)
            return R.ok();
        return R.error();
    }
    //修改数据
    @PostMapping("update")
    public R updateCateBrand(@RequestBody TbCategoryBrand tbCategoryBrand){
        boolean flag = categoryBrandService.updateById(tbCategoryBrand);
        if (flag)
            return R.ok();
        return R.error();
    }

    //删除数据
    @GetMapping("delete")
    public R deleteCateBrandById(@RequestParam("id") int id){
        boolean flag = categoryBrandService.removeById(id);
        if (flag)
            return R.ok();
        return R.error();
    }
}

